package com.yanqu.road.server.cmd.monopolymarket;

import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.monopolymarket.MonopolyMarketModule;
import com.yanqu.road.server.manger.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/11 16:32
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_NOTICE_BROADCAST_FROM_CROSS, desc = "下发公告广播 跨服返回区服 协议")
public class MonopolyMarketNoticeBroadcastFromCrossCmd implements Command {


    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        MonopolyMarketProto.BroadcastMonopolyMarketRespMsg noticeBroadcast = MonopolyMarketProto.BroadcastMonopolyMarketRespMsg.parseFrom(packet.getBytes());
        if(MonopolyMarketMgr.group == null){
            return;
        }
        List<GamePlayer> onlinePlayer = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer player : onlinePlayer){
            MonopolyMarketModule monopolyMarketModule = player.getModule(MonopolyMarketModule.class);
            if(monopolyMarketModule.inSystemId == noticeBroadcast.getNewNotice().getType()){
                player.sendPacket(ClientProtocol.U_MONOPOLY_MARKET_BROADCAST, noticeBroadcast.toBuilder());
            }
        }
    }
}
